package com.example.demo.controller;

import javax.servlet.http.HttpServletRequest;

import org.keycloak.KeycloakSecurityContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.example.demo.domain.Result;

@RestController
public class Hello {
	@GetMapping("/vanilla")
	public String hello() {

		return "Hello world";
	}
	
	@GetMapping("/api")
	public Result api() {
		Result result = new Result();
		result.setResult("hello world");
		return result;
	}

	@GetMapping("/context")
	public String context(HttpServletRequest request) {
		KeycloakSecurityContext keycloakSecurityContext = (KeycloakSecurityContext) request
				.getAttribute(KeycloakSecurityContext.class.getName());
		System.out.println(keycloakSecurityContext.getRealm());
		return keycloakSecurityContext.getRealm() + " " + keycloakSecurityContext.getIdTokenString();

		/*
		 * httpServletRequest.getSession()
		 * .getAttribute(KeycloakSecurityContext.class.getName());
		 */
	}
	@GetMapping("/logout3")
	public ModelAndView logout3() {
		ModelAndView modelAndView = new ModelAndView("redirect:/logout4");
		return modelAndView;
	}


}
